﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;

namespace AnyOffice.general.attend.personal
{
    public partial class remark : ModulePage
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int dutyId = (Request.QueryString["duty_id"] != null) ? Convert.ToInt32(Request.QueryString["duty_id"].ToString()) : 0;
                this.ViewState["DutyId"] = dutyId;
                DataTable table = new AttendDutyDao().SelectByDutyId(base.Conn, dutyId);
                if (table.Rows.Count == 0)
                {
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowPromptClose("无考勤记录");
                    return;
                }
                if (table.Rows[0]["UserId"].ToString() != base.User.Identity.Name)
                {
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowPromptClose("无考勤记录");
                    return;
                }
                if ((Convert.ToDateTime(table.Rows[0]["RegisterTime"].ToString()) < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00")) || (Convert.ToDateTime(table.Rows[0]["RegisterTime"].ToString()) > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59")))
                {
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowPromptClose("无考勤记录");
                    return;
                }
                if (table.Rows[0]["Remark"] != DBNull.Value)
                {
                    this.txtRemark.Text = table.Rows[0]["Remark"].ToString();
                }
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                new AttendDutyDao().Update(base.Conn, Convert.ToInt32(this.ViewState["DutyId"].ToString()), this.txtRemark.Text);
                this.litMessage.Text = base.ShowPromptClose("保存成功！");
                Response.Write("<script>self.close();</script>");
            }
        }
 

    }
}
